package com.smart.ZC.Tools;

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Rect;

import com.smart.ZC.Data.data;

public class Tools {
	public Tools() {

	}

	public static short data_readShort(DataInputStream is) {
		short[] b = new short[2];
		short data = -1;
		try {
			b[0] = (short) is.readUnsignedByte();
			b[1] = (short) is.readUnsignedByte();
			data = (short) (b[0] | (b[1] << 8));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}

	public static int data_readInt(DataInputStream is) {
		int[] b = new int[4];
		int data = -1;
		try {
			b[0] = (short) is.readUnsignedByte();
			b[1] = (short) is.readUnsignedByte();
			b[2] = (short) is.readUnsignedByte();
			b[3] = (short) is.readUnsignedByte();
			data = (short) (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}

	public static Rect getBlock(int actorID, int actionID, int animationID,
			int child) {
		int i = 0;
		short x_obset, y_obset;
		short tmp_objItem;
		Rect blockRect = new Rect();

		while (data.ced_nDrawPos[data.ced_npcItem[actorID][actionID][animationID][i]][0] != dConfig.BACK_PIC) {
			i += 3;
		}

		tmp_objItem = data.ced_npcItem[actorID][actionID][animationID][i
				+ child * 3];
		x_obset = data.ced_npcItem[actorID][actionID][animationID][i + child
				* 3 + 1];
		y_obset = data.ced_npcItem[actorID][actionID][animationID][i + child
				* 3 + 2];

		blockRect.left = (dConfig.screen_width >> 1) + x_obset
				- data.ced_nDrawPos[tmp_objItem][3] / 2;
		blockRect.top = (dConfig.screen_height >> 1) + y_obset
				- data.ced_nDrawPos[tmp_objItem][4] / 2;
		blockRect.right = data.ced_nDrawPos[tmp_objItem][3];
		blockRect.bottom = data.ced_nDrawPos[tmp_objItem][4];

		return blockRect;
	}

	public static int setFlag(int IsGameRunPaint, int flag) {
		// TODO Auto-generated method stub
		return IsGameRunPaint | flag;
	}

	public static boolean TestFlag(int IsGameRunPaint, int flag) {
		// TODO Auto-generated method stub
		return (IsGameRunPaint & flag) != 0;
	}

	public static int ClearFlag(int IsGameRunPaint, int flag) {
		return IsGameRunPaint &= ~flag;
	}

	public static int getRandom(int low, int high) {
		int random;// =(int) Math.random();
		random = (int) (Math.random() * (high - low) + low);
		return random;
	}
}
